<?php
 // Copyright (C) 2010-2011 Aron Racho <aron@mi-squred.com>
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
 // as published by the Free Software Foundation; either version 2
 // of the License, or (at your option) any later version.
?>
<html>
<head>
    <?php html_header_show();?>
    <link rel="stylesheet" href="<?php echo $GLOBALS['css_header'] ?>" type="text/css">
	<script type="text/javascript" src="<?php echo $web_root; ?>/library/js/jquery-1.10.0.min.js"></script> 
    <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/js/jquery.js"></script>
    <link rel="stylesheet" href="<?php css_src('rules.css') ?>" type="text/css">
	<link rel="stylesheet" href="<?php echo $web_root; ?>/patients/css/jquery.autocomplete.css" type="text/css"/>
	<script type="text/javascript" src="<?php echo $web_root; ?>/patients/js/jquery.autocomplete.js"></script>

</head>

<body class='body_top'>
<?php $rule = $viewBean->rule ?>
<?php $criteria = $viewBean->criteria ?>

<script language="javascript" src="<?php js_src('edit.js') ?>"></script>
<script type="text/javascript">

		function cancel(){
$("#info2").hide();
	var vari = $("#rule_id").val();
	var url = '../super/rules/index.php?action=detail!view&id='+vari;
	$.get(url, 
		function(data){
			$("#info").html(data);
		});	
		$("#info").show();
	}
	function save_new(){
		$.post( "../super/rules/index.php?action=edit!submit_criteria", $( "#frm_submit" ).serialize());
		$("#info").hide();
		$("#info2").show();		
	}
</script>

<table class="header">
  <tr>
        <td class="title"><?php echo out( xl( 'Rule Edit' ) ); ?></td>
        <td>
            <!--a href="index.php?action=detail!view&id=<?php echo out( $rule->id ); ?>" class="iframe_medium css_button" onclick="top.restoreSession()">
                <span><?php echo out( xl( 'Cancel' ) ); ?></span>
            </a-->
			<!--a href="#" class="iframe_medium css_button" onclick="top.restoreSession();cancel();">
                <span><?php echo out( xl( 'Cancel' ) ); ?></span>
            </a-->
			<input type='button' value='<?php echo out( xl( 'Cancel' ) ); ?>' onclick='cancel();'>
			</input>
            <!--a href="#" class="iframe_medium css_button" id="btn_save" onclick="top.restoreSession();save_new();"><span><?php echo out( xl( 'Save' ) ); ?></span></a-->
			<input type='button' value='<?php echo out( xl( 'Save' ) ); ?>' onclick='save_new();'>
			</input>
        </td>
  </tr>
</table>

<div class="rule_detail edit text">

    <form action="index.php?action=edit!submit_criteria" method="post" id="frm_submit" onsubmit="return top.restoreSession()">
    <input type="hidden" name="id" id="rule_id" value="<?php echo out( $rule->id ); ?>"/>
    <input type="hidden" name="group_id" value="<?php echo out( $criteria->groupId ); ?>"/>
    <input type="hidden" name="guid" value="<?php echo out( $criteria->guid ); ?>"/>
    <input type="hidden" name="type" value="<?php echo out( $viewBean->type ); ?>"/>
    <input type="hidden" name="criteriaTypeCode" value="<?php echo out( $criteria->criteriaType->code ); ?>"/>

    <!-- ----------------- -->
    <?php
    if ( file_exists($viewBean->_view_body) ) {
        require_once($viewBean->_view_body);
    }
    ?>
    <!-- ----------------- -->

    </form>
    
</div>

<div id="required_msg" class="small">
    <span class="required">*</span><?php echo out( xl( 'Required fields' ) ); ?>
</div>

</body>

</html>
